package com.shh.rabbitmq.service;


import javax.websocket.EncodeException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shh.rabbitmq.dao.OrderDao;
import com.shh.rabbitmq.dao.OrderMsgDao;
import com.shh.rabbitmq.domin.OrderDO;
import com.shh.rabbitmq.domin.OrderMsgDO;

@Service
public class MakeOrderService {
	@Autowired
	private OrderDao orderDao;
	
	@Autowired
	private OrderMsgDao orderMsgDao;
	
	//模拟用户下单
	@Transactional(rollbackFor = EncodeException.class)//开启事务
    public void makeOrder(OrderDO orderDO){
        //1.保存订单数据
		orderDao.addOrder(orderDO);
        //2.保存订单消息记录
		OrderMsgDO orderMsg = new OrderMsgDO();
		orderMsg.setOrderNo(orderDO.getOrderNo());
		orderMsg.setOrderState(0);
		orderMsgDao.addOrder(orderMsg);
    }
	
}
